/***************************************************************************
创建者：田昱民
 开始时间：               : 2016.12.01
 copyright            : (C) 华友高科
 修改说明：（每次有修改就添加一条，带有 修改人，修改时间，修改描述）

 ***************************************************************************
*   电机状态窗口程序
*                                                                         *
 ***************************************************************************/
#include "motorstatusview.h"
#include "ui_motorstatusview.h"
#include "domparser.h"
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#define D_VALID_RANGE_RATIO 2  //10有点卡


MotorStatusView::MotorStatusView(PingPongBuffer *pingPongBufferIn, int jointNumber,int robotId
                                 ,bool isAutoSaveWaveIn, QWidget *parent) :
    QWidget(parent),
    ui(new Ui::MotorStatusView)
{
    ui->setupUi(this);
//    setWindowFlags(Qt::CustomizeWindowHint);
    QString tmpStyleSheet="QComboBox {border: 1px solid gray;border-radius: 3px;padding: 1px 2px 1px 2px; selection-background-color: rgb(44 , 137 , 255);}";
    setStyleSheet(tmpStyleSheet);
    isAutoSaveWave=isAutoSaveWaveIn;
    QString tmpStr="weave-robotId ";
    tmpStr+=QString::number(robotId);
    setWindowTitle(tmpStr);
#ifdef D_USE_ROS
    isForAgv=true;
#else
    isForAgv=false;
#endif

    int timerCount;
    if(isForAgv)
    {
        timerCount=300;
        delayCountMax=10;
        validMaxDataLength=3000;
        ui->setDefaultSelect_ros();
        maxDataQueueSize=1000;
    }
    else
    {
        timerCount=300;
        delayCountMax=10;
        validMaxDataLength=10000;//30000会导致没有coredump的SIGKILl
    //    ui->setDefaultSelect_robotArm();//设置示波器初始显示。
        ui->setDefaultSelect_robotArmVel();//显示反馈速度
        maxDataQueueSize=10000;
    }

    isReceiveInnerWaveData=true;
    delayCount=0;
    isDelayStop=false;

    graphFlag=1;
    debugFlag=0;

    minYAxis = -0.00005;
    maxYAxis = 0.00005;
    clickedX=0;
    clickedY=0;
    pingPongBuffer=pingPongBufferIn;
    mathDataQueue=new QQueue<MathDataInfo>;
    mathDataQueue_file=new QQueue<MathDataInfo>;
    recordFilePath=D_TCRCONTROLLER_DATA_PATH;
    recordFilePath+=ROBOT_COMMON_NAME+QString::number( robotId )+"/wave/";

    timer = new QTimer();
    connect(timer,SIGNAL(timeout()),this,SLOT(timeroutslot()));//timeoutslot()为自定义槽

    timer->start(timerCount);
    plotFlag = 0;
    axisCount = jointNumber;

    maxValue.resize(8);
    minValue.resize(8);
    for(int g=0;g<8;g++)
    {
          maxValue[g] = -1e10;
          minValue[g] = 1e10;
    }


    initGraphView();
}

MotorStatusView::~MotorStatusView()
{

}

int MotorStatusView::clearMessage()
{
    qDebug() << "MotorStatusView::clearMessage ";
    isDelayStop=false;
    delayCount=0;
    isReceiveInnerWaveData=true;
    return 1;
}

int MotorStatusView::saveWaveDataToFile(QString filePath)
{
//    return saveMathDataToXmlFile(mathDataQueue,filePath);
//    return saveMathDataToHuayouFile(mathDataQueue,filePath);
    return saveMathDataToJsonFile(mathDataQueue,filePath);
}



int MotorStatusView::openRecordFile(QString filePathIn)
{
//    return readMathDataFromXmlFile(filePathIn,*mathDataQueue);
//    return readMathDataFromHuayouFile(filePathIn,*mathDataQueue_file);
    return readMathDataFromJsonFile(filePathIn,*mathDataQueue_file);
}

int MotorStatusView::plotFileWave()
{
    return plotWave(mathDataQueue_file);
}

int MotorStatusView::plotInnerWave()
{
    return plotWave(mathDataQueue);
}

int MotorStatusView::plotWave(QQueue<MathDataInfo> *mathDataQueueIn)
{
    qDebug() << "MotorStatusView::plotWave ";
    resetPlot();

    if(0==mathDataQueueIn->size())
    {
        qDebug() << "error, 0==mathDataQueueIn->size() ";
        return 0;
    }

    QVector<int> axisNumberList;
    QVector<int> dataTypeList;
    QVector<int> checkBoxList;
    QVector<double> magnificationList;
    int isDiffChecked;

        axisNumberList.resize(8);
        dataTypeList.resize(18);
        checkBoxList.resize(8);
        magnificationList.resize(8);
        axisNumberList[0] = ui->blue_index_comboBox->currentIndex();
        axisNumberList[1] = ui->red_index_comboBox->currentIndex();
        axisNumberList[2] = ui->green_index_comboBox->currentIndex();
        axisNumberList[3] = ui->black_index_comboBox->currentIndex();
        axisNumberList[4] = ui->yellow_index_comboBox->currentIndex();
        axisNumberList[5] = ui->darkBlue_index_comboBox->currentIndex();
        axisNumberList[6] = ui->darkRed_index_comboBox->currentIndex();
        axisNumberList[7] = ui->darkGreen_index_comboBox->currentIndex();
        dataTypeList[0]=ui->blue_comboBox->currentIndex();
        dataTypeList[1]=ui->red_comboBox->currentIndex();
        dataTypeList[2]=ui->green_comboBox->currentIndex();
        dataTypeList[3]=ui->black_comboBox->currentIndex();
        dataTypeList[4]=ui->yellow_comboBox->currentIndex();
        dataTypeList[5]=ui->darkBlue_comboBox->currentIndex();
        dataTypeList[6]=ui->darkRed_comboBox->currentIndex();
        dataTypeList[7]=ui->darkGreen_comboBox->currentIndex();
        checkBoxList[0] = ui->checkBox1->isChecked();
        checkBoxList[1] = ui->checkBox2->isChecked();
        checkBoxList[2] = ui->checkBox3->isChecked();
        checkBoxList[3] = ui->checkBox4->isChecked();
        checkBoxList[4] = ui->checkBox5->isChecked();
        checkBoxList[5] = ui->checkBox6->isChecked();
        checkBoxList[6] = ui->checkBox7->isChecked();
        checkBoxList[7] = ui->checkBox8->isChecked();
        magnificationList[0] = ui->magnification1->text().toDouble();
        magnificationList[1] = ui->magnification2->text().toDouble();
        magnificationList[2] = ui->magnification3->text().toDouble();
        magnificationList[3] = ui->magnification4->text().toDouble();
        magnificationList[4] = ui->magnification5->text().toDouble();
        magnificationList[5] = ui->magnification6->text().toDouble();
        magnificationList[6] = ui->magnification7->text().toDouble();
        magnificationList[7] = ui->magnification8->text().toDouble();

        isDiffChecked= ui->checkBoxDiff->isChecked();


        for (int j = 0; j < mathDataQueueIn->size(); j++)
        {
            for (int i = 0; i < 8; i++)
            {

                    addOneTimeData((*mathDataQueueIn)[j],checkBoxList[i],i,dataTypeList[i],axisNumberList[i],magnificationList[i],isDiffChecked);

            }
        }



            for(int g=0;g<8;g++)
            {
                //            if (pingPongBuffer->buffer[pingPongBuffer->currentReadBufferIndex].timeStamp[0][1999] > 8000)
                //            {
                //              ui->customPlot->graph(g)->removeDataBefore(pingPongBuffer->buffer[pingPongBuffer->currentReadBufferIndex].timeStamp[0][1999]-2000);//保留长度(当前时间-32) 即为长度32,若注释,数据一直保留
                //            }
                ui->customPlot->graph(g)->rescaleValueAxis();
                if (maxValue[g] > maxYAxis)
                {
                    maxYAxis = maxValue[g];
                }
                if (minValue[g] < minYAxis)
                {
                    minYAxis = minValue[g];
                }
            }
            ui->maxValue1->setText(QString::number(maxValue[0],'f',3));//"%1").arg(maxValue[0], 0, "g", 3));
            ui->minValue1->setText(QString::number(minValue[0],'f',3));
            ui->maxValue2->setText(QString::number(maxValue[1],'f',3));
            ui->minValue2->setText(QString::number(minValue[1],'f',3));
            ui->maxValue3->setText(QString::number(maxValue[2],'f',3));
            ui->minValue3->setText(QString::number(minValue[2],'f',3));
            ui->maxValue4->setText(QString::number(maxValue[3],'f',3));
            ui->minValue4->setText(QString::number(minValue[3],'f',3));
            ui->maxValue5->setText(QString::number(maxValue[4],'f',3));
            ui->minValue5->setText(QString::number(minValue[4],'f',3));
            ui->maxValue6->setText(QString::number(maxValue[5],'f',3));
            ui->minValue6->setText(QString::number(minValue[5],'f',3));
            ui->maxValue7->setText(QString::number(maxValue[6],'f',3));
            ui->minValue7->setText(QString::number(minValue[6],'f',3));
            ui->maxValue8->setText(QString::number(maxValue[7],'f',3));
            ui->minValue8->setText(QString::number(minValue[7],'f',3));
            ui->customPlot->xAxis->setRange(mathDataQueueIn->last().timeStamp,
                    mathDataQueueIn->size(),Qt::AlignRight);

            float threshold1, threshold2;
            if (minYAxis > 0)
            {
                threshold1 = 0.5;
            }
            else
            {
                threshold1 = 1.5;
            }
            if (maxYAxis > 0)
            {
                threshold2 = 1.5;
            }
            else
            {
                threshold2 = 0.5;
            }
            ui->customPlot->yAxis->setRange(minYAxis*threshold1,maxYAxis*threshold2);
            ui->customPlot->replot();//hualei coredump ?


}

int MotorStatusView::setDebugFlag(int debugFlagIn)
{
    debugFlag=debugFlagIn;
    return 1;
}

void MotorStatusView::initGraphView()
{
//    ui->blue_comboBox->addItem("blue");
//    ui->red_comboBox->addItem("red");
//    ui->green_comboBox->addItem("green");
//    ui->black_comboBox->addItem("black");
//    ui->yellow_comboBox->addItem("yellow");


    //setStyleSheet("background-color:white;");
    ui->backwidget->setStyleSheet("background-color:white;");

    rubberBand = new QRubberBand(QRubberBand::Rectangle, ui->customPlot);
    ui->data->setText("y:");


    ui->customPlot->addGraph();
    ui->customPlot->graph(0)->setPen(QPen(Qt::blue));
    ui->customPlot->addGraph();
    ui->customPlot->graph(1)->setPen(QPen(Qt::red));
    ui->customPlot->addGraph();
    ui->customPlot->graph(2)->setPen(QPen(Qt::green));
    ui->customPlot->addGraph();
    ui->customPlot->graph(3)->setPen(QPen(Qt::black));
    ui->customPlot->addGraph();
    ui->customPlot->graph(4)->setPen(QPen(Qt::yellow));
    ui->customPlot->addGraph();
    ui->customPlot->graph(5)->setPen(QPen(Qt::cyan));
    ui->customPlot->addGraph();
    ui->customPlot->graph(6)->setPen(QPen(Qt::magenta));
    ui->customPlot->addGraph();
    ui->customPlot->graph(7)->setPen(QPen(Qt::lightGray));

    ui->customPlot->xAxis->setTickLabelType(QCPAxis::ltNumber);
    ui->customPlot->xAxis->setDateTimeFormat("|");
    ui->customPlot->xAxis->setAutoTickStep(false);
//    ui->customPlot->xAxis->setTickStep(100);
    ui->customPlot->xAxis->setTickStep(1);
    ui->customPlot->axisRect()->setupFullAxesBox();

    ui->customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables);
    connect(ui->customPlot, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(mousePress(QMouseEvent*)));
    connect(ui->customPlot, SIGNAL(mouseMove(QMouseEvent*)), this, SLOT(mouseMove(QMouseEvent*)));
    connect(ui->customPlot, SIGNAL(mouseRelease(QMouseEvent*)), this, SLOT(mouseRelease(QMouseEvent*)));
    connect(ui->customPlot->xAxis, SIGNAL(rangeChanged(QCPRange)), ui->customPlot->xAxis2, SLOT(setRange(QCPRange)));
    connect(ui->customPlot->yAxis, SIGNAL(rangeChanged(QCPRange)), ui->customPlot->yAxis2, SLOT(setRange(QCPRange)));

    ui->tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
    model = new QStandardItemModel();
    ui->tableView->setModel(model);
    model->setColumnCount(11);
    ui->tableView->setColumnWidth(0,40);
    ui->tableView->setColumnWidth(1,65);
    ui->tableView->setColumnWidth(2,50);
    ui->tableView->setColumnWidth(3,65);
    ui->tableView->setColumnWidth(4,65);
    ui->tableView->setColumnWidth(5,65);
    ui->tableView->setColumnWidth(6,95);
    ui->tableView->setColumnWidth(7,95);
    ui->tableView->setColumnWidth(8,95);
    ui->tableView->setColumnWidth(9,95);
    ui->tableView->setColumnWidth(10,95);
    ui->tableView->verticalHeader()->hide();
    QHeaderView *headerView = ui->tableView->horizontalHeader();
    //headerView->setResizeMode(QHeaderView::Fixed);
    model->setHeaderData(0,Qt::Horizontal,tr("轴"));
    model->setHeaderData(1,Qt::Horizontal,tr("位置"));
    model->setHeaderData(2,Qt::Horizontal,tr("速度"));
    model->setHeaderData(3,Qt::Horizontal,tr("力距"));
    model->setHeaderData(4,Qt::Horizontal,tr("误差"));
    model->setHeaderData(5,Qt::Horizontal,tr("功率"));
    model->setHeaderData(6,Qt::Horizontal,tr("位置最大值"));
    model->setHeaderData(7,Qt::Horizontal,tr("速度最大值"));
    model->setHeaderData(8,Qt::Horizontal,tr("力距最大值"));
    model->setHeaderData(9,Qt::Horizontal,tr("误差最大值"));
    model->setHeaderData(10,Qt::Horizontal,tr("功率最大值"));

    for(int i = 0 ;i<D_ROBOT_AXIS_MAX;i++)
    {
        model->setItem(i,0,new QStandardItem(QString::number(i+1)));
        model->setItem(i,1,new QStandardItem(""));
        model->setItem(i,2,new QStandardItem(""));
        model->setItem(i,3,new QStandardItem(""));
        model->setItem(i,4,new QStandardItem(""));
        model->setItem(i,5,new QStandardItem(""));
        model->setItem(i,6,new QStandardItem(""));
        model->setItem(i,7,new QStandardItem(""));
        model->setItem(i,8,new QStandardItem(""));
        model->setItem(i,9,new QStandardItem(""));
        model->setItem(i,10,new QStandardItem(""));
    }
}

void MotorStatusView::mousePress(QMouseEvent* mevent)
{
    if(mevent->button() == Qt::RightButton)
    {
        rubberOrigin = mevent->pos();
        rubberBand->setGeometry(QRect(rubberOrigin, QSize()));
        rubberBand->show();
    }
    else if(mevent->button() == Qt::LeftButton)
    {
        double pos_y = ui->customPlot->yAxis->pixelToCoord(mevent->pos().y());
        double pos_x = ui->customPlot->xAxis->pixelToCoord(mevent->pos().x());
        clickedX=pos_x;
        clickedY=pos_y;
        QString strInfo="点X:";
        strInfo+=QString::number(pos_x,'f',3);
        strInfo+=" Y:"+QString::number(pos_y,'f',3);
        ui->data->setText(strInfo);
    }
    else
    {

    }
}

void MotorStatusView::mouseMove(QMouseEvent *mevent)
{
    if(rubberBand->isVisible())
    {
        rubberBand->setGeometry(QRect(rubberOrigin, mevent->pos()).normalized());
    }
    else
    {

    }
}

void MotorStatusView::mouseRelease(QMouseEvent *mevent)
{
    Q_UNUSED(mevent);
    if (rubberBand->isVisible())
    {
        const QRect zoomRect = rubberBand->geometry();
        int xp1, yp1, xp2, yp2;
        zoomRect.getCoords(&xp1, &yp1, &xp2, &yp2);
        double x1 = ui->customPlot->xAxis->pixelToCoord(xp1);
        double x2 = ui->customPlot->xAxis->pixelToCoord(xp2);
        double y1 = ui->customPlot->yAxis->pixelToCoord(yp1);
        double y2 = ui->customPlot->yAxis->pixelToCoord(yp2);

        ui->customPlot->xAxis->setRange(x1, x2);
        ui->customPlot->yAxis->setRange(y1, y2);

        rubberBand->hide();
        ui->customPlot->replot();
    }
    else
    {

    }
}


void MotorStatusView::updateMotorStatusView()
{
    emit showMotorStatus();
}

void MotorStatusView::updateView()
{
    for(int n = 0;n<6;n++)//for(int n=0;n<axisCount;n++)
    {
        if(n < axisCount)
        {
            //QString s=QString::number(n);
            QString s1 = QString::number(value0[n],'d',2);
            QString s2 = QString::number(value1[n],'d',2);
            QString s3 = QString::number(value2[n],'d',2);
            QString s4 = QString::number(value3[n],'d',2);
            QString s5 = QString::number(value4[n],'d',2);
            QString s6 = QString::number(valueMax0[n],'d',3);//QString::number(value5[n]);
            QString s7 = QString::number(valueMax1[n],'d',3);//QString::number(value6[n]);
            QString s8 = QString::number(valueMax2[n],'d',3);//QString::number(value7[n]);
            QString s9 = QString::number(valueMax3[n],'d',3);//QString::number(value8[n]);
            QString s10 = QString::number(valueMax4[n],'d',3);//QString::number(value9[n]);

            //model->item(n,0)->setText(s);
            if(model->item(n,1)->text() != s1)
            {
                model->item(n,1)->setText(s1);
            }
            if(model->item(n,2)->text() != s2)
            {
                model->item(n,2)->setText(s2);
            }
            if(model->item(n,3)->text() != s3)
            {
                model->item(n,3)->setText(s3);
            }
            if(model->item(n,4)->text() != s4)
            {
                model->item(n,4)->setText(s4);
            }
            if(model->item(n,5)->text() != s5)
            {
                model->item(n,5)->setText(s5);
            }
            if(model->item(n,6)->text() != s6)
            {
                model->item(n,6)->setText(s6);
            }
            if(model->item(n,7)->text() != s7)
            {
                model->item(n,7)->setText(s7);
            }
            if(model->item(n,8)->text() != s8)
            {
                model->item(n,8)->setText(s8);
            }
            if(model->item(n,9)->text() != s9)
            {
                model->item(n,9)->setText(s9);
            }
            if(model->item(n,10)->text() != s10)
            {
                model->item(n,10)->setText(s10);
            }
        }
    }
}

void MotorStatusView::timeroutslot()
{
    if(1==debugFlag)
    {
        qDebug()<<"MotorStatusView::timeroutslot() In";
    }

    if(isDelayStop && delayCount<=delayCountMax)
    {
//        qDebug()<<"true==isDelayStop delayCount"<<delayCount;
        delayCount++;
    }
    if(delayCount==delayCountMax)
    {
        isReceiveInnerWaveData=false;
        if (plotFlag == 1)
        {
            ceaseWave();//只允许执行一次
        }
        if(isAutoSaveWave)
        {
//            QDateTime current_date_time =QDateTime::currentDateTime();
//            QString tmpFilePath=recordFilePath+"wave"+current_date_time.toString("yyyy.MM.dd-hh:mm:ss");
            QString tmpFilePath=recordFilePath+"wave_autoSave";
    //        saveMathDataToXmlFile(mathDataQueue,tmpFilePath);
//            saveMathDataToHuayouFile(mathDataQueue,tmpFilePath);
              saveMathDataToJsonFile(mathDataQueue,tmpFilePath);
        }


    }


    if (plotFlag == 1)
    {
        receiveWaveData(true);//默认不要开启波形图显示。
    }
    else
    {
        if(isReceiveInnerWaveData)
        {
            receiveWaveData(false);
        }

    }
    if(1==debugFlag)
    {
        qDebug()<<"MotorStatusView::timeroutslot() Out";
    }

    setButtonStyle(plotFlag);

    //qDebug() << "--------------  --------------timeroutslot------------------------------";
}
//D_WAVE_AXIS_SIZE
#define D_SAVE_AXIS_SIZE 8 //保存数量

int MotorStatusView::saveMathDataToJsonFile(QQueue<MathDataInfo> *mathDataQueue, QString filePath)
{
    qDebug() << "MotorStatusView::saveMathDataToJsonFile begin,,,";

    //创建文件
    QFile file(filePath);

    //存在打开，不存在创建
    file.open(QIODevice::WriteOnly | QIODevice::Text);//设置为只读，保证以前文件内容被清空。

    //发送信息
    QJsonObject obj_root;
    QJsonObject obj_level1;
    QJsonArray arry_itemList;
    for(int k=0;k<mathDataQueue->size();k++)
    {
        QJsonObject obj_item;

        QString tmpNodeName;

        tmpNodeName="timeStamp";
        obj_item.insert(tmpNodeName, (*mathDataQueue)[k].timeStamp);


        if(false== isForAgv)
        {
            if(1)
            {
                for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                {
                    tmpNodeName="position_command"+QString::number(i);
                    obj_item.insert(tmpNodeName, QJsonValue((*mathDataQueue)[k].position_command[i]));
                }
                for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                {
                    tmpNodeName="velocity_command"+QString::number(i);
                    obj_item.insert(tmpNodeName, (*mathDataQueue)[k].velocity_command[i]);
                }
                for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                {
                    tmpNodeName="torque_command"+QString::number(i);
                    obj_item.insert(tmpNodeName, (*mathDataQueue)[k].torque_command[i]);
                }
                for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                {
                    tmpNodeName="position_feedback"+QString::number(i);
                    obj_item.insert(tmpNodeName, (*mathDataQueue)[k].position_feedback[i]);
                }
                for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                {
                    tmpNodeName="velocity_feedback"+QString::number(i);
                    obj_item.insert(tmpNodeName, (*mathDataQueue)[k].velocity_feedback[i]);
                }
                for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                {
                    tmpNodeName="torque_feedback"+QString::number(i);
                    obj_item.insert(tmpNodeName, (*mathDataQueue)[k].torque_feedback[i]);
                }
                for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                {
                    tmpNodeName="position_followOffset"+QString::number(i);
                    obj_item.insert(tmpNodeName, QJsonValue((*mathDataQueue)[k].position_followOffset[i]));
                }
                for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                {
                    tmpNodeName="velocity_followOffset"+QString::number(i);
                    obj_item.insert(tmpNodeName, (*mathDataQueue)[k].velocity_followOffset[i]);
                }
                for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                {
                    tmpNodeName="torque_followOffset"+QString::number(i);
                    obj_item.insert(tmpNodeName, (*mathDataQueue)[k].torque_followOffset[i]);
                }

                for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                {
                    tmpNodeName="velocity_offset_command"+QString::number(i);
                    obj_item.insert(tmpNodeName, (*mathDataQueue)[k].velocity_offset_command[i]);
                }
                for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                {
                    tmpNodeName="torque_offset_command"+QString::number(i);
                    obj_item.insert(tmpNodeName, (*mathDataQueue)[k].torque_offset_command[i]);
                }
                for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                {
                    tmpNodeName="torque_offset_command"+QString::number(i);
                    obj_item.insert(tmpNodeName, (*mathDataQueue)[k].torque_offset_command[i]);
                }

                for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                {
                    tmpNodeName="aDin"+QString::number(i);
                    obj_item.insert(tmpNodeName, (*mathDataQueue)[k].aDin[i]);
                }
            }


            //
            if(0)
            {
                for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                {
                    tmpNodeName="position_command_puls"+QString::number(i);
                    obj_item.insert(tmpNodeName, (*mathDataQueue)[k].position_command_puls[i]);
                }
                for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                {
                    tmpNodeName="velocity_command_puls"+QString::number(i);
                    obj_item.insert(tmpNodeName, (*mathDataQueue)[k].velocity_command_puls[i]);
                }
                for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                {
                    tmpNodeName="torque_command_puls"+QString::number(i);
                    obj_item.insert(tmpNodeName, (*mathDataQueue)[k].torque_command_puls[i]);
                }
                for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                {
                    tmpNodeName="position_feedback_puls"+QString::number(i);
                    obj_item.insert(tmpNodeName, (*mathDataQueue)[k].position_feedback_puls[i]);
                }
                for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                {
                    tmpNodeName="velocity_feedback_puls"+QString::number(i);
                    obj_item.insert(tmpNodeName, (*mathDataQueue)[k].velocity_feedback_puls[i]);
                }
                for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                {
                    tmpNodeName="torque_feedback_puls"+QString::number(i);
                    obj_item.insert(tmpNodeName, (*mathDataQueue)[k].torque_feedback_puls[i]);
                }
                for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                {
                    tmpNodeName="position_followOffset_puls"+QString::number(i);
                    obj_item.insert(tmpNodeName, (*mathDataQueue)[k].position_followOffset_puls[i]);
                }
                for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                {
                    tmpNodeName="velocity_followOffset_puls"+QString::number(i);
                    obj_item.insert(tmpNodeName, (*mathDataQueue)[k].velocity_followOffset_puls[i]);
                }
                for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                {
                    tmpNodeName="torque_followOffset_puls"+QString::number(i);
                    obj_item.insert(tmpNodeName, (*mathDataQueue)[k].torque_followOffset_puls[i]);
                }

                for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                {
                    tmpNodeName="velocity_offset_command_puls"+QString::number(i);
                    obj_item.insert(tmpNodeName, (*mathDataQueue)[k].velocity_offset_command_puls[i]);
                }
                for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                {
                    tmpNodeName="torque_offset_command_puls"+QString::number(i);
                    obj_item.insert(tmpNodeName, (*mathDataQueue)[k].torque_offset_command_puls[i]);
                }
            }

        }
        else
        {
            for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
            {
                tmpNodeName="vehiclePositionCommand"+QString::number(i);
                obj_item.insert(tmpNodeName, (*mathDataQueue)[k].vehiclePositionCommand[i]);
            }
            for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
            {
                tmpNodeName="vehiclePositionFeedback"+QString::number(i);
                obj_item.insert(tmpNodeName, (*mathDataQueue)[k].vehiclePositionFeedback[i]);
            }
            obj_item.insert("deltaDistance_x", (*mathDataQueue)[k].deltaDistance_x);
            obj_item.insert("deltaDistance_y", (*mathDataQueue)[k].deltaDistance_y);
            obj_item.insert("deltaAngle", (*mathDataQueue)[k].deltaAngle);
            obj_item.insert("absoluteDistance", (*mathDataQueue)[k].absoluteDistance);
            obj_item.insert("absoluteAngle", (*mathDataQueue)[k].absoluteAngle);
            obj_item.insert("anglePidOutput", (*mathDataQueue)[k].anglePidOutput);
            obj_item.insert("xPidOutput", (*mathDataQueue)[k].xPidOutput);
            obj_item.insert("yPidOutput", (*mathDataQueue)[k].yPidOutput);
            obj_item.insert("calculateBiasType", (*mathDataQueue)[k].calculateBiasType);
        }


        arry_itemList.append(obj_item);
    }

    obj_level1.insert("wave_list", arry_itemList);

    obj_root.insert("wave_info", obj_level1);


    QJsonDocument jsonDoc(obj_root);
    QString tmpString=jsonDoc.toJson();

    //写入内容,这里需要转码，否则报错。
//    QByteArray str = tmpString.toUtf8();
     QByteArray str = tmpString.toLatin1();
    //写入QByteArray格式字符串
    file.write(str);

    //关闭文件
    file.close();
    file.flush();
    qDebug() << "MotorStatusView::saveMathDataToJsonFile end,,,";
    return 1;

}

int MotorStatusView::saveMathDataToXmlFile(QQueue<MathDataInfo> *mathDataQueue, QString filePath)
{
    qDebug() << "MotorStatusView::saveMathDataToXmlFile begin,,,";

    //创建文件
    initial_forXmlFile(filePath);


    DomParser domParser;

    bool ok = domParser.openXml(filePath, QIODevice::ReadWrite );
    if( !ok )//无法打开机器人数据文件！
    {
        qDebug() << "open file error";
        return -1;
    }

    qDebug()<<"mathDataQueue.size()="<<mathDataQueue->size();
    for(int i=0;i<mathDataQueue->size();i++)
    {
        saveOneMathDataToXmlFile(&domParser,(*mathDataQueue)[i]);
    }

    domParser.closeXml(true);//保存
    qDebug() << "MotorStatusView::saveMathDataToXmlFile end";


    return 1;
}

int MotorStatusView::saveMathDataToHuayouFile(QQueue<MathDataInfo> *mathDataQueue, QString filePath)
{
     qDebug() << "MotorStatusView::saveMathDataToHuayouFile begin,,,";

         QFile file(filePath);
         if(file.open(QIODevice::WriteOnly))
         {
             QDataStream out(&file);
             out.setVersion(QDataStream::Qt_5_6);
             quint32 tmpSize = mathDataQueue->size();
             out << tmpSize;
     //        qDebug() <<__LINE__ <<"====tmpSize=="<<tmpSize;
             for(quint32 i=0; i<tmpSize;i++)
             {
                 for(int k=0;k<D_WAVE_AXIS_SIZE;k++)
                 {
                     out << (*mathDataQueue)[i].timeStamp;
                     out << (*mathDataQueue)[i].position_command;
                     out << (*mathDataQueue)[i].velocity_command;
                     out << (*mathDataQueue)[i].torque_command;
                     out << (*mathDataQueue)[i].position_feedback;
                     out << (*mathDataQueue)[i].velocity_feedback;
                     out << (*mathDataQueue)[i].torque_feedback;
                     out << (*mathDataQueue)[i].position_followOffset;
                     out << (*mathDataQueue)[i].velocity_followOffset;
                     out << (*mathDataQueue)[i].torque_followOffset;
                     out << (*mathDataQueue)[i].velocity_offset_command;
                     out << (*mathDataQueue)[i].torque_offset_command;
                     out << (*mathDataQueue)[i].position_command_puls;
                     out << (*mathDataQueue)[i].velocity_command_puls;
                     out << (*mathDataQueue)[i].torque_command_puls;
                     out << (*mathDataQueue)[i].position_feedback_puls;
                     out << (*mathDataQueue)[i].velocity_feedback_puls;
                     out << (*mathDataQueue)[i].torque_feedback_puls;
                     out << (*mathDataQueue)[i].position_followOffset_puls;
                     out << (*mathDataQueue)[i].velocity_followOffset_puls;
                     out << (*mathDataQueue)[i].torque_followOffset_puls;
                     out << (*mathDataQueue)[i].velocity_offset_command_puls;
                     out << (*mathDataQueue)[i].torque_offset_command_puls;
                     out << (*mathDataQueue)[i].vehiclePositionCommand;
                     out << (*mathDataQueue)[i].vehiclePositionFeedback;

                 }
                    out << (*mathDataQueue)[i].deltaDistance_x;
                    out << (*mathDataQueue)[i].deltaDistance_y;
                    out << (*mathDataQueue)[i].absoluteDistance;
                    out << (*mathDataQueue)[i].absoluteAngle;
                    out << (*mathDataQueue)[i].anglePidOutput;
                    out << (*mathDataQueue)[i].xPidOutput;
                    out << (*mathDataQueue)[i].yPidOutput;

             }
             file.close();
             file.flush();//必须加，如果不加，可能关机的时候丢失文件内容。
             qDebug() << "MotorStatusView::saveMathDataToHuayouFile end,,,";
             return 1;
         }
         return -1;
}

int MotorStatusView::readMathDataFromXmlFile(QString filePath, QQueue<MathDataInfo> &mathDataQueue)
{
    qDebug() << "MotorStatusView::readMathDataFromXmlFile start,,,";

        DomParser domParser;
        bool ok = domParser.openXml(filePath, QIODevice::ReadOnly );
        if( !ok )
        {
           // 打开失败
           qDebug()<<"error no log file"<<filePath;
           return -1;
        }

        // 查找日志信息主节点
        QDomNode  mainNode = domParser.findSubNode(domParser.getRootDomElement(), "log", ok );
        if( !ok )
        {
           qDebug()<<"error no log node";
           return -1;
        }

        // 获取子节点列表
        QDomNodeList devNodes = mainNode.childNodes();

        // 遍历获取子节点日志信息
        MathDataInfo tmpInfo;
        QString tmpNodeName;
        for (int i=0;i<devNodes.size();i++)
        {



           // 读取日志文件节点内容

                tmpNodeName="timeStamp";
                domParser.readXml( domParser.findSubNode(devNodes.at(i), tmpNodeName, ok ), tmpInfo.timeStamp );

            for(int j=0;j<D_WAVE_AXIS_SIZE;j++)
            {
                tmpNodeName="position_command"+QString::number(i);
                domParser.readXml( domParser.findSubNode(devNodes.at(i), tmpNodeName, ok ), tmpInfo.position_command[j] );
            }
            for(int j=0;j<D_WAVE_AXIS_SIZE;j++)
            {
                tmpNodeName="velocity_command"+QString::number(i);
                domParser.readXml( domParser.findSubNode(devNodes.at(i), tmpNodeName, ok ), tmpInfo.velocity_command[j] );
            }
            for(int j=0;j<D_WAVE_AXIS_SIZE;j++)
            {
                tmpNodeName="torque_command"+QString::number(i);
                domParser.readXml( domParser.findSubNode(devNodes.at(i), tmpNodeName, ok ), tmpInfo.torque_command[j] );
            }
            for(int j=0;j<D_WAVE_AXIS_SIZE;j++)
            {
                tmpNodeName="position_feedback"+QString::number(i);
                domParser.readXml( domParser.findSubNode(devNodes.at(i), tmpNodeName, ok ), tmpInfo.position_feedback[j] );
            }
            for(int j=0;j<D_WAVE_AXIS_SIZE;j++)
            {
                tmpNodeName="velocity_feedback"+QString::number(i);
                domParser.readXml( domParser.findSubNode(devNodes.at(i), tmpNodeName, ok ), tmpInfo.velocity_feedback[j] );
            }
            for(int j=0;j<D_WAVE_AXIS_SIZE;j++)
            {
                tmpNodeName="torque_feedback"+QString::number(i);
                domParser.readXml( domParser.findSubNode(devNodes.at(i), tmpNodeName, ok ), tmpInfo.torque_feedback[j] );
            }

            for(int j=0;j<D_WAVE_AXIS_SIZE;j++)
            {
                tmpNodeName="position_followOffset"+QString::number(i);
                domParser.readXml( domParser.findSubNode(devNodes.at(i), tmpNodeName, ok ), tmpInfo.position_followOffset[j] );
            }
            for(int j=0;j<D_WAVE_AXIS_SIZE;j++)
            {
                tmpNodeName="velocity_followOffset"+QString::number(i);
                domParser.readXml( domParser.findSubNode(devNodes.at(i), tmpNodeName, ok ), tmpInfo.velocity_followOffset[j] );
            }
            for(int j=0;j<D_WAVE_AXIS_SIZE;j++)
            {
                tmpNodeName="torque_followOffset"+QString::number(i);
                domParser.readXml( domParser.findSubNode(devNodes.at(i), tmpNodeName, ok ), tmpInfo.torque_followOffset[j] );
            }
            for(int j=0;j<D_WAVE_AXIS_SIZE;j++)
            {
                tmpNodeName="velocity_offset_command"+QString::number(i);
                domParser.readXml( domParser.findSubNode(devNodes.at(i), tmpNodeName, ok ), tmpInfo.velocity_offset_command[j] );
            }
            for(int j=0;j<D_WAVE_AXIS_SIZE;j++)
            {
                tmpNodeName="torque_offset_command"+QString::number(i);
                domParser.readXml( domParser.findSubNode(devNodes.at(i), tmpNodeName, ok ), tmpInfo.torque_offset_command[j] );
            }

            //
            for(int j=0;j<D_WAVE_AXIS_SIZE;j++)
            {
                tmpNodeName="position_command_puls"+QString::number(i);
                domParser.readXml( domParser.findSubNode(devNodes.at(i), tmpNodeName, ok ), tmpInfo.position_command_puls[j] );
            }
            for(int j=0;j<D_WAVE_AXIS_SIZE;j++)
            {
                tmpNodeName="velocity_command_puls"+QString::number(i);
                domParser.readXml( domParser.findSubNode(devNodes.at(i), tmpNodeName, ok ), tmpInfo.velocity_command_puls[j] );
            }
            for(int j=0;j<D_WAVE_AXIS_SIZE;j++)
            {
                tmpNodeName="torque_command_puls"+QString::number(i);
                domParser.readXml( domParser.findSubNode(devNodes.at(i), tmpNodeName, ok ), tmpInfo.torque_command_puls[j] );
            }
            for(int j=0;j<D_WAVE_AXIS_SIZE;j++)
            {
                tmpNodeName="position_feedback_puls"+QString::number(i);
                domParser.readXml( domParser.findSubNode(devNodes.at(i), tmpNodeName, ok ), tmpInfo.position_feedback_puls[j] );
            }
            for(int j=0;j<D_WAVE_AXIS_SIZE;j++)
            {
                tmpNodeName="velocity_feedback_puls"+QString::number(i);
                domParser.readXml( domParser.findSubNode(devNodes.at(i), tmpNodeName, ok ), tmpInfo.velocity_feedback_puls[j] );
            }
            for(int j=0;j<D_WAVE_AXIS_SIZE;j++)
            {
                tmpNodeName="torque_feedback_puls"+QString::number(i);
                domParser.readXml( domParser.findSubNode(devNodes.at(i), tmpNodeName, ok ), tmpInfo.torque_feedback_puls[j] );
            }

            //
            for(int j=0;j<D_WAVE_AXIS_SIZE;j++)
            {
                tmpNodeName="position_followOffset_puls"+QString::number(i);
                domParser.readXml( domParser.findSubNode(devNodes.at(i), tmpNodeName, ok ), tmpInfo.position_followOffset_puls[j] );
            }
            for(int j=0;j<D_WAVE_AXIS_SIZE;j++)
            {
                tmpNodeName="velocity_followOffset_puls"+QString::number(i);
                domParser.readXml( domParser.findSubNode(devNodes.at(i), tmpNodeName, ok ), tmpInfo.velocity_followOffset_puls[j] );
            }
            for(int j=0;j<D_WAVE_AXIS_SIZE;j++)
            {
                tmpNodeName="torque_followOffset_puls"+QString::number(i);
                domParser.readXml( domParser.findSubNode(devNodes.at(i), tmpNodeName, ok ), tmpInfo.torque_followOffset_puls[j] );
            }
            for(int j=0;j<D_WAVE_AXIS_SIZE;j++)
            {
                tmpNodeName="velocity_offset_command_puls"+QString::number(i);
                domParser.readXml( domParser.findSubNode(devNodes.at(i), tmpNodeName, ok ), tmpInfo.velocity_offset_command_puls[j] );
            }
            for(int j=0;j<D_WAVE_AXIS_SIZE;j++)
            {
                tmpNodeName="torque_offset_command_puls"+QString::number(i);
                domParser.readXml( domParser.findSubNode(devNodes.at(i), tmpNodeName, ok ), tmpInfo.torque_offset_command_puls[j] );
            }
            for(int j=0;j<D_WAVE_AXIS_SIZE;j++)
            {
                tmpNodeName="vehiclePositionCommand"+QString::number(i);
                domParser.readXml( domParser.findSubNode(devNodes.at(i), tmpNodeName, ok ), tmpInfo.vehiclePositionCommand[j] );
            }
            for(int j=0;j<D_WAVE_AXIS_SIZE;j++)
            {
                tmpNodeName="vehiclePositionFeedback"+QString::number(i);
                domParser.readXml( domParser.findSubNode(devNodes.at(i), tmpNodeName, ok ), tmpInfo.vehiclePositionFeedback[j] );
            }

            //

           domParser.readXml( domParser.findSubNode(devNodes.at(i), "deltaDistance_x", ok ), tmpInfo.deltaDistance_x );
           domParser.readXml( domParser.findSubNode(devNodes.at(i), "deltaDistance_y", ok ), tmpInfo.deltaDistance_y );
           domParser.readXml( domParser.findSubNode(devNodes.at(i), "deltaAngle", ok ), tmpInfo.deltaAngle );
           domParser.readXml( domParser.findSubNode(devNodes.at(i), "absoluteDistance", ok ), tmpInfo.absoluteDistance );
           domParser.readXml( domParser.findSubNode(devNodes.at(i), "absoluteAngle", ok ), tmpInfo.absoluteAngle );
           domParser.readXml( domParser.findSubNode(devNodes.at(i), "anglePidOutput", ok ), tmpInfo.anglePidOutput );
           domParser.readXml( domParser.findSubNode(devNodes.at(i), "xPidOutput", ok ), tmpInfo.xPidOutput );
           domParser.readXml( domParser.findSubNode(devNodes.at(i), "yPidOutput", ok ), tmpInfo.yPidOutput );

           mathDataQueue.enqueue(tmpInfo);

        }

        domParser.closeXml();

        return 1;
}

int MotorStatusView::readMathDataFromHuayouFile(QString filePath, QQueue<MathDataInfo> &mathDataQueue)
{
    qDebug() << "MotorStatusView::readMathDataFromHuayouFile start,,,";
    mathDataQueue.clear();
    QFile file(filePath);
    if(file.exists())
    {
        if(file.open(QIODevice::ReadOnly))
        {
            QDataStream in(&file);
            in.setVersion(QDataStream::Qt_5_6);
            quint32 tmpSize;
            in >> tmpSize;

            MathDataInfo tmpData;
            for(quint32 i=0; i< tmpSize;i++)
            {
                in >> tmpData.timeStamp;
                for(int k=0;k<D_WAVE_AXIS_SIZE;k++)
                {

                    in >> tmpData.position_command[k];
                    in >> tmpData.velocity_command[k];
                    in >> tmpData.torque_command[k];
                    in >> tmpData.position_feedback[k];
                    in >> tmpData.velocity_feedback[k];
                    in >> tmpData.torque_feedback[k];
                    in >> tmpData.position_followOffset[k];
                    in >> tmpData.velocity_followOffset[k];
                    in >> tmpData.torque_followOffset[k];
                    in >> tmpData.velocity_offset_command[k];
                    in >> tmpData.torque_offset_command[k];
                    in >> tmpData.position_command_puls[k];
                    in >> tmpData.velocity_command_puls[k];
                    in >> tmpData.torque_command_puls[k];
                    in >> tmpData.position_feedback_puls[k];
                    in >> tmpData.velocity_feedback_puls[k];
                    in >> tmpData.torque_feedback_puls[k];
                    in >> tmpData.position_followOffset_puls[k];
                    in >> tmpData.velocity_followOffset_puls[k];
                    in >> tmpData.torque_followOffset_puls[k];
                    in >> tmpData.velocity_offset_command_puls[k];
                    in >> tmpData.torque_offset_command_puls[k];
                    in >> tmpData.vehiclePositionCommand[k];
                    in >> tmpData.vehiclePositionFeedback[k];

                }
                   in >> tmpData.deltaDistance_x;
                   in >> tmpData.deltaDistance_y;
                   in >> tmpData.absoluteDistance;
                   in >> tmpData.absoluteAngle;
                   in >> tmpData.anglePidOutput;
                   in >> tmpData.xPidOutput;
                   in >> tmpData.yPidOutput;
                mathDataQueue.enqueue(tmpData);
            }
            file.close();
            file.flush();//必须加，如果不加，可能关机的时候丢失文件内容。
            qDebug() << "MotorStatusView::readMathDataFromHuayouFile end,,,";
            return 1;
        }
    }
    else
    {
        return -1;
    }
    return -1;
}

int MotorStatusView::readMathDataFromJsonFile(QString filePath, QQueue<MathDataInfo> &mathDataQueue)
{

    qDebug() << "MotorStatusView::readMathDataFromJsonFile start,,,";
    mathDataQueue.clear();
    QFile file(filePath);
    if(file.exists())
    {
        if(file.open(QIODevice::ReadOnly))
        {

            QByteArray receiveByteArry = file.read(file.bytesAvailable());
            QJsonParseError jsonError;
            QJsonDocument receiveJsonDoc = QJsonDocument::fromJson(receiveByteArry, &jsonError);
            if(jsonError.error != QJsonParseError::NoError )
            {
              qDebug() << "JsonFile error "<<jsonError.error;
            }
            QJsonObject redeiveJsonObj = receiveJsonDoc.object();


            QJsonObject obj_level1=redeiveJsonObj.value("wave_info").toObject();
            QJsonArray arry_itemList=obj_level1.value("wave_list").toArray();


            for(int k=0;k<arry_itemList.size();k++)
            {
                MathDataInfo tmp_info;
                QJsonObject obj_item=arry_itemList[k].toObject();

                QString tmpNodeName;

                    tmpNodeName="timeStamp";
                    tmp_info.timeStamp=obj_item[tmpNodeName].toDouble();

                if(false== isForAgv)
                {
                    if(1)
                    {

                        for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                        {
                            tmpNodeName="position_command"+QString::number(i);
                            tmp_info.position_command[i]=obj_item[tmpNodeName].toDouble();
                        }
                        for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                        {
                            tmpNodeName="velocity_command"+QString::number(i);
                            tmp_info.velocity_command[i]=obj_item[tmpNodeName].toDouble();
                        }
                        for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                        {
                            tmpNodeName="torque_command"+QString::number(i);
                            tmp_info.torque_command[i]=obj_item[tmpNodeName].toDouble();
                        }

                        for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                        {
                            tmpNodeName="position_feedback"+QString::number(i);
                            tmp_info.position_feedback[i]=obj_item[tmpNodeName].toDouble();
                        }
                        for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                        {
                            tmpNodeName="velocity_feedback"+QString::number(i);
                            tmp_info.velocity_feedback[i]=obj_item[tmpNodeName].toDouble();
                        }

                        for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                        {
                            tmpNodeName="torque_feedback"+QString::number(i);
                            tmp_info.torque_feedback[i]=obj_item[tmpNodeName].toDouble();
                        }
                        for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                        {
                            tmpNodeName="position_followOffset"+QString::number(i);
                            tmp_info.position_followOffset[i]=obj_item[tmpNodeName].toDouble();
                        }

                        for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                        {
                            tmpNodeName="velocity_followOffset"+QString::number(i);
                            tmp_info.velocity_followOffset[i]=obj_item[tmpNodeName].toDouble();
                        }
                        for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                        {
                            tmpNodeName="torque_followOffset"+QString::number(i);
                            tmp_info.torque_followOffset[i]=obj_item[tmpNodeName].toDouble();
                        }

                        for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                        {
                            tmpNodeName="velocity_offset_command"+QString::number(i);
                            tmp_info.velocity_offset_command[i]=obj_item[tmpNodeName].toDouble();
                        }
                        for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                        {
                            tmpNodeName="torque_offset_command"+QString::number(i);
                            tmp_info.torque_offset_command[i]=obj_item[tmpNodeName].toDouble();
                        }
                        for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                        {
                            tmpNodeName="aDin"+QString::number(i);
                            tmp_info.aDin[i]=obj_item[tmpNodeName].toDouble();
                        }



                    }

                    //
                    if(0)
                    {


                        for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                        {
                            tmpNodeName="position_command_puls"+QString::number(i);
                            tmp_info.position_command_puls[i]=obj_item[tmpNodeName].toDouble();
                        }
                        for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                        {
                            tmpNodeName="velocity_command_puls"+QString::number(i);
                            tmp_info.velocity_command_puls[i]=obj_item[tmpNodeName].toDouble();
                        }
                        for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                        {
                            tmpNodeName="torque_command_puls"+QString::number(i);
                            tmp_info.torque_command_puls[i]=obj_item[tmpNodeName].toDouble();
                        }

                        for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                        {
                            tmpNodeName="position_feedback_puls"+QString::number(i);
                            tmp_info.position_feedback_puls[i]=obj_item[tmpNodeName].toDouble();
                        }
                        for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                        {
                            tmpNodeName="velocity_feedback_puls"+QString::number(i);
                            tmp_info.velocity_feedback_puls[i]=obj_item[tmpNodeName].toDouble();
                        }

                        for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                        {
                            tmpNodeName="torque_feedback_puls"+QString::number(i);
                            tmp_info.torque_feedback_puls[i]=obj_item[tmpNodeName].toDouble();
                        }
                        for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                        {
                            tmpNodeName="position_followOffset_puls"+QString::number(i);
                            tmp_info.position_followOffset_puls[i]=obj_item[tmpNodeName].toDouble();
                        }

                        for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                        {
                            tmpNodeName="velocity_followOffset_puls"+QString::number(i);
                            tmp_info.velocity_followOffset_puls[i]=obj_item[tmpNodeName].toDouble();
                        }
                        for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                        {
                            tmpNodeName="torque_followOffset_puls"+QString::number(i);
                            tmp_info.torque_followOffset_puls[i]=obj_item[tmpNodeName].toDouble();
                        }

                        for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                        {
                            tmpNodeName="velocity_offset_command_puls"+QString::number(i);
                            tmp_info.velocity_offset_command_puls[i]=obj_item[tmpNodeName].toDouble();
                        }
                        for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                        {
                            tmpNodeName="torque_offset_command_puls"+QString::number(i);
                            tmp_info.torque_offset_command_puls[i]=obj_item[tmpNodeName].toDouble();
                        }

                    }

                }
                else
                {
                    for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                    {
                        tmpNodeName="vehiclePositionCommand"+QString::number(i);
                        tmp_info.vehiclePositionCommand[i]=obj_item[tmpNodeName].toDouble();
                    }


                    for(int i=0;i<D_SAVE_AXIS_SIZE;i++)
                    {
                        tmpNodeName="vehiclePositionFeedback"+QString::number(i);
                        tmp_info.vehiclePositionFeedback[i]=obj_item[tmpNodeName].toDouble();
                    }

                    tmp_info.deltaDistance_x=obj_item["deltaDistance_x"].toDouble();
                    tmp_info.deltaDistance_y=obj_item["deltaDistance_y"].toDouble();
                    tmp_info.deltaAngle=obj_item["deltaAngle"].toDouble();
                    tmp_info.absoluteDistance=obj_item["absoluteDistance"].toDouble();
                    tmp_info.absoluteAngle=obj_item["absoluteAngle"].toDouble();
                    tmp_info.anglePidOutput=obj_item["anglePidOutput"].toDouble();
                    tmp_info.xPidOutput=obj_item["xPidOutput"].toDouble();
                    tmp_info.yPidOutput=obj_item["yPidOutput"].toDouble();
                }


                mathDataQueue.append(tmp_info);
            }



            file.close();
        }
    }

    return 1;
}



int MotorStatusView::initial_forXmlFile(QString xmlLogFileNameIn)
{
    QFile file(xmlLogFileNameIn);
    //定义文件内容字符串
    QString content= "<common>  <log>  </log>  </common>";

    //存在打开，不存在创建
    file.open(QIODevice::ReadWrite | QIODevice::Text);
    //写入内容,这里需要转码，否则报错。
    QByteArray str = content.toUtf8();
    //写入QByteArray格式字符串
    file.write(str);

    //关闭文件
    file.close();
    return 1;

}




int MotorStatusView::saveOneMathDataToXmlFile(DomParser *domParser,MathDataInfo log)
{
    ///读内部轴参数
    bool ok;
    QDomNode  mainNode = domParser->findSubNode(domParser->getRootDomElement(), "log", ok );
    if( !ok )
    {
       qDebug()<<"error no log node";
        return -1;
    }


    domParser->addNode(mainNode,"record","");
    QDomNode  recordNode;
    QDomNodeList devNodes = mainNode.childNodes();
    recordNode=devNodes.at(devNodes.size()-1);

    QString tmpNodeName;

        tmpNodeName="timeStamp";
        domParser->addNode(recordNode,tmpNodeName,log.timeStamp);

    for(int i=0;i<D_WAVE_AXIS_SIZE;i++)
    {
        tmpNodeName="position_command"+QString::number(i);
        domParser->addNode(recordNode,tmpNodeName,log.position_command[i]);
    }
    for(int i=0;i<D_WAVE_AXIS_SIZE;i++)
    {
        tmpNodeName="velocity_command"+QString::number(i);
        domParser->addNode(recordNode,tmpNodeName,log.velocity_command[i]);
    }
    for(int i=0;i<D_WAVE_AXIS_SIZE;i++)
    {
        tmpNodeName="torque_command"+QString::number(i);
        domParser->addNode(recordNode,tmpNodeName,log.torque_command[i]);
    }
    for(int i=0;i<D_WAVE_AXIS_SIZE;i++)
    {
        tmpNodeName="velocity_feedback"+QString::number(i);
        domParser->addNode(recordNode,tmpNodeName,log.velocity_feedback[i]);
    }
    for(int i=0;i<D_WAVE_AXIS_SIZE;i++)
    {
        tmpNodeName="position_feedback"+QString::number(i);
        domParser->addNode(recordNode,tmpNodeName,log.position_feedback[i]);
    }
    for(int i=0;i<D_WAVE_AXIS_SIZE;i++)
    {
        tmpNodeName="torque_feedback"+QString::number(i);
        domParser->addNode(recordNode,tmpNodeName,log.torque_feedback[i]);
    }
    for(int i=0;i<D_WAVE_AXIS_SIZE;i++)
    {
        tmpNodeName="position_followOffset"+QString::number(i);
        domParser->addNode(recordNode,tmpNodeName,log.position_followOffset[i]);
    }
    for(int i=0;i<D_WAVE_AXIS_SIZE;i++)
    {
        tmpNodeName="velocity_followOffset"+QString::number(i);
        domParser->addNode(recordNode,tmpNodeName,log.velocity_followOffset[i]);
    }
    for(int i=0;i<D_WAVE_AXIS_SIZE;i++)
    {
        tmpNodeName="torque_followOffset"+QString::number(i);
        domParser->addNode(recordNode,tmpNodeName,log.torque_followOffset[i]);
    }
    for(int i=0;i<D_WAVE_AXIS_SIZE;i++)
    {
        tmpNodeName="velocity_offset_command"+QString::number(i);
        domParser->addNode(recordNode,tmpNodeName,log.velocity_offset_command[i]);
    }
    for(int i=0;i<D_WAVE_AXIS_SIZE;i++)
    {
        tmpNodeName="torque_offset_command"+QString::number(i);
        domParser->addNode(recordNode,tmpNodeName,log.torque_offset_command[i]);
    }

    for(int i=0;i<D_WAVE_AXIS_SIZE;i++)
    {
        tmpNodeName="position_command_puls"+QString::number(i);
        domParser->addNode(recordNode,tmpNodeName,log.position_command_puls[i]);
    }
    for(int i=0;i<D_WAVE_AXIS_SIZE;i++)
    {
        tmpNodeName="velocity_command_puls"+QString::number(i);
        domParser->addNode(recordNode,tmpNodeName,log.velocity_command_puls[i]);
    }
    for(int i=0;i<D_WAVE_AXIS_SIZE;i++)
    {
        tmpNodeName="torque_command_puls"+QString::number(i);
        domParser->addNode(recordNode,tmpNodeName,log.torque_command_puls[i]);
    }
    for(int i=0;i<D_WAVE_AXIS_SIZE;i++)
    {
        tmpNodeName="position_feedback_puls"+QString::number(i);
        domParser->addNode(recordNode,tmpNodeName,log.position_feedback_puls[i]);
    }
    for(int i=0;i<D_WAVE_AXIS_SIZE;i++)
    {
        tmpNodeName="velocity_feedback_puls"+QString::number(i);
        domParser->addNode(recordNode,tmpNodeName,log.velocity_feedback_puls[i]);
    }
    for(int i=0;i<D_WAVE_AXIS_SIZE;i++)
    {
        tmpNodeName="torque_feedback_puls"+QString::number(i);
        domParser->addNode(recordNode,tmpNodeName,log.torque_feedback_puls[i]);
    }
    for(int i=0;i<D_WAVE_AXIS_SIZE;i++)
    {
        tmpNodeName="position_followOffset_puls"+QString::number(i);
        domParser->addNode(recordNode,tmpNodeName,log.position_followOffset_puls[i]);
    }
    for(int i=0;i<D_WAVE_AXIS_SIZE;i++)
    {
        tmpNodeName="velocity_followOffset_puls"+QString::number(i);
        domParser->addNode(recordNode,tmpNodeName,log.velocity_followOffset_puls[i]);
    }
    for(int i=0;i<D_WAVE_AXIS_SIZE;i++)
    {
        tmpNodeName="torque_followOffset_puls"+QString::number(i);
        domParser->addNode(recordNode,tmpNodeName,log.torque_followOffset_puls[i]);
    }
    for(int i=0;i<D_WAVE_AXIS_SIZE;i++)
    {
        tmpNodeName="velocity_offset_command_puls"+QString::number(i);
        domParser->addNode(recordNode,tmpNodeName,log.velocity_offset_command_puls[i]);
    }
    for(int i=0;i<D_WAVE_AXIS_SIZE;i++)
    {
        tmpNodeName="torque_offset_command_puls"+QString::number(i);
        domParser->addNode(recordNode,tmpNodeName,log.torque_offset_command_puls[i]);
    }
    for(int i=0;i<D_WAVE_AXIS_SIZE;i++)
    {
        tmpNodeName="vehiclePositionCommand"+QString::number(i);
        domParser->addNode(recordNode,tmpNodeName,log.vehiclePositionCommand[i]);
    }
    for(int i=0;i<D_WAVE_AXIS_SIZE;i++)
    {
        tmpNodeName="vehiclePositionFeedback"+QString::number(i);
        domParser->addNode(recordNode,tmpNodeName,log.vehiclePositionFeedback[i]);
    }

    domParser->addNode(recordNode,"deltaDistance_x",log.deltaDistance_x);
    domParser->addNode(recordNode,"deltaDistance_y",log.deltaDistance_y);
    domParser->addNode(recordNode,"deltaAngle",log.deltaAngle);
    domParser->addNode(recordNode,"absoluteDistance",log.absoluteDistance);
    domParser->addNode(recordNode,"absoluteAngle",log.absoluteAngle);
    domParser->addNode(recordNode,"anglePidOutput",log.anglePidOutput);
    domParser->addNode(recordNode,"xPidOutput",log.xPidOutput);
    domParser->addNode(recordNode,"yPidOutput",log.yPidOutput);


    return 1;

}


int MotorStatusView::startWave()
{
    qDebug()<<"startWave()";
    //开始
    ui->horizontalSlider->setValue(5);
    ui->horizontalSlider->setEnabled(0);
    plotFlag = 1;
    isDelayStop=false;
    delayCount=0;
    isReceiveInnerWaveData=true;

    return 1;
}

int MotorStatusView::ceaseWave()
{
    qDebug()<<"stopWave()";
    //暂停
    ui->horizontalSlider->setEnabled(1);
    plotFlag = 2;
    isDelayStop=false;
    isReceiveInnerWaveData=false;

    return 1;
}

int MotorStatusView::stopWave_delay()
{
//     qDebug()<<"stopWave_delay()";
     isDelayStop=true;
     return 1;
}

int MotorStatusView::resetPlot()
{
    //清除
    isReceiveInnerWaveData=false;
    plotFlag = 0;
    for(int g=0;g<8;g++)
    {
          ui->customPlot->graph(g)->removeDataBefore(0);
          ui->customPlot->graph(g)->removeDataAfter(0);
          maxValue[g] = -1e10;
          minValue[g] = 1e10;
    }
    minYAxis = -0.00005;
    maxYAxis = 0.00005;
    ui->maxValue1->setText(QString("%1").arg(maxValue[0]));
    ui->minValue1->setText(QString("%1").arg(minValue[0]));
    ui->maxValue2->setText(QString("%1").arg(maxValue[1]));
    ui->minValue2->setText(QString("%1").arg(minValue[1]));
    ui->maxValue3->setText(QString("%1").arg(maxValue[2]));
    ui->minValue3->setText(QString("%1").arg(minValue[2]));
    ui->maxValue4->setText(QString("%1").arg(maxValue[3]));
    ui->minValue4->setText(QString("%1").arg(minValue[3]));
    ui->maxValue5->setText(QString("%1").arg(maxValue[4]));
    ui->minValue5->setText(QString("%1").arg(minValue[4]));
    ui->maxValue6->setText(QString("%1").arg(maxValue[5]));
    ui->minValue6->setText(QString("%1").arg(minValue[5]));
    ui->maxValue7->setText(QString("%1").arg(maxValue[6]));
    ui->minValue7->setText(QString("%1").arg(minValue[6]));
    ui->maxValue8->setText(QString("%1").arg(maxValue[7]));
    ui->minValue8->setText(QString("%1").arg(minValue[7]));
    ui->customPlot->xAxis->setRange(0,100);

    float threshold1, threshold2;
    if (minYAxis > 0)
    {
        threshold1 = 0.5;
    }
    else
    {
        threshold1 = 1.5;
    }
    if (maxYAxis > 0)
    {
        threshold2 = 1.5;
    }
    else
    {
        threshold2 = 0.5;
    }
    ui->customPlot->yAxis->setRange(minYAxis*threshold1,maxYAxis*threshold2);
    ui->customPlot->replot();
}


void MotorStatusView::on_pushButton_clicked()
{
    startWave();
}

void MotorStatusView::on_pushButton_2_clicked()
{
    ceaseWave();
}

void MotorStatusView::on_pushButton_3_clicked()
{
    resetPlot();

}

void MotorStatusView::update()
{
//    double key = QDateTime::currentDateTime().toMSecsSinceEpoch()/1000.0;//当前时间
//    mainKey = key;

//    if(graphFlag==1)
//    {
//        for(int x=1;x<axisCount+1;x++)
//        {
//            QString l=QString::number(x);
//            ui->blue_comboBox->addItem(l);
//            ui->red_comboBox->addItem(l);
//            ui->green_comboBox->addItem(l);
//            ui->black_comboBox->addItem(l);
//            ui->yellow_comboBox->addItem(l);
//        }
//        graphFlag=0;
//    }

//    for(int n=0;n<axisCount+2;n++)
//    {
//        if(ui->blue_comboBox->currentIndex()==n)
//        {
//            if(n==0)
//            {}
//            else
//            {
//                ui->customPlot->graph(0)->addData(key, value0[n-1]);
//            }
//        }

//        if(ui->red_comboBox->currentIndex()==n)
//        {
//            if(n==0)
//            {}
//            else
//            {
//                ui->customPlot->graph(1)->addData(key, value1[n-1]);
//            }
//        }

//        if(ui->green_comboBox->currentIndex()==n)
//        {
//            if(n==0)
//            {}
//            else
//            {
//                ui->customPlot->graph(2)->addData(key, value2[n-1]);
//            }
//        }

//        if(ui->yellow_comboBox->currentIndex()==n)
//        {
//            if(n==0)
//            {}
//            else
//            {
//                ui->customPlot->graph(3)->addData(key, value3[n-1]);
//            }
//        }

//        if(ui->black_comboBox->currentIndex()==n)
//        {
//            if(n==0)
//            {}
//            else
//            {
//                ui->customPlot->graph(4)->addData(key, value4[n-1]);
//            }
//        }
//    }

//    for(int g=0;g<5;g++)
//    {
//        ui->customPlot->graph(g)->removeDataBefore(key-32);//保留长度(当前时间-32) 即为长度32,若注释,数据一直保留
//        ui->customPlot->graph(g)->rescaleValueAxis();
//    }
//    ui->customPlot->xAxis->setRange(key+1.25,8,Qt::AlignRight);//界面显示多少数据(中间,8秒)
//    ui->customPlot->replot();
}

void MotorStatusView::receiveWaveData(bool isPlot)
{
    if(NULL==pingPongBuffer)
    {
        return;
    }

    QVector<int> axisNumberList;
    QVector<int> dataTypeList;
    QVector<int> checkBoxList;
    QVector<double> magnificationList;
    int isDiffChecked;
    if(isPlot)
    {
        axisNumberList.resize(8);
        dataTypeList.resize(18);
        checkBoxList.resize(8);
        magnificationList.resize(8);
        axisNumberList[0] = ui->blue_index_comboBox->currentIndex();
        axisNumberList[1] = ui->red_index_comboBox->currentIndex();
        axisNumberList[2] = ui->green_index_comboBox->currentIndex();
        axisNumberList[3] = ui->black_index_comboBox->currentIndex();
        axisNumberList[4] = ui->yellow_index_comboBox->currentIndex();
        axisNumberList[5] = ui->darkBlue_index_comboBox->currentIndex();
        axisNumberList[6] = ui->darkRed_index_comboBox->currentIndex();
        axisNumberList[7] = ui->darkGreen_index_comboBox->currentIndex();
        dataTypeList[0]=ui->blue_comboBox->currentIndex();
        dataTypeList[1]=ui->red_comboBox->currentIndex();
        dataTypeList[2]=ui->green_comboBox->currentIndex();
        dataTypeList[3]=ui->black_comboBox->currentIndex();
        dataTypeList[4]=ui->yellow_comboBox->currentIndex();
        dataTypeList[5]=ui->darkBlue_comboBox->currentIndex();
        dataTypeList[6]=ui->darkRed_comboBox->currentIndex();
        dataTypeList[7]=ui->darkGreen_comboBox->currentIndex();
        checkBoxList[0] = ui->checkBox1->isChecked();
        checkBoxList[1] = ui->checkBox2->isChecked();
        checkBoxList[2] = ui->checkBox3->isChecked();
        checkBoxList[3] = ui->checkBox4->isChecked();
        checkBoxList[4] = ui->checkBox5->isChecked();
        checkBoxList[5] = ui->checkBox6->isChecked();
        checkBoxList[6] = ui->checkBox7->isChecked();
        checkBoxList[7] = ui->checkBox8->isChecked();
        magnificationList[0] = ui->magnification1->text().toDouble();
        magnificationList[1] = ui->magnification2->text().toDouble();
        magnificationList[2] = ui->magnification3->text().toDouble();
        magnificationList[3] = ui->magnification4->text().toDouble();
        magnificationList[4] = ui->magnification5->text().toDouble();
        magnificationList[5] = ui->magnification6->text().toDouble();
        magnificationList[6] = ui->magnification7->text().toDouble();
        magnificationList[7] = ui->magnification8->text().toDouble();

        isDiffChecked= ui->checkBoxDiff->isChecked();
    }



    if (pingPongBuffer->currentReadBufferIndex != pingPongBuffer->currentWriteBufferIndex)
    {
        int readIndex=pingPongBuffer->currentReadBufferIndex;
        for (int j = 0; j < pingPongBuffer->bufferValidateDataLength; j++)
        {
            //队列缓存
            mathDataQueue->enqueue(pingPongBuffer->buffer[pingPongBuffer->currentReadBufferIndex].mathData[j]);
            if(maxDataQueueSize<mathDataQueue->size())
            {
                mathDataQueue->dequeue();
            }
            for (int i = 0; i < 8; i++)
            {
                if(isPlot)
                {
                    MathDataInfo tmpMathData=pingPongBuffer->buffer[readIndex].mathData[j];
                    addOneTimeData(tmpMathData,checkBoxList[i],i,dataTypeList[i],axisNumberList[i],magnificationList[i],isDiffChecked);
                }
            }
        }

        if (pingPongBuffer->currentReadBufferIndex == 0)
        {
            pingPongBuffer->currentReadBufferIndex = 1;
        }
        else
        {
            pingPongBuffer->currentReadBufferIndex = 0;
        }

        if(isPlot)
        {
            for(int g=0;g<8;g++)
            {
                //            if (pingPongBuffer->buffer[pingPongBuffer->currentReadBufferIndex].timeStamp[0][1999] > 8000)
                //            {
                //              ui->customPlot->graph(g)->removeDataBefore(pingPongBuffer->buffer[pingPongBuffer->currentReadBufferIndex].timeStamp[0][1999]-2000);//保留长度(当前时间-32) 即为长度32,若注释,数据一直保留
                //            }
                ui->customPlot->graph(g)->rescaleValueAxis();
                if (maxValue[g] > maxYAxis)
                {
                    maxYAxis = maxValue[g];
                }
                if (minValue[g] < minYAxis)
                {
                    minYAxis = minValue[g];
                }
            }
            ui->maxValue1->setText(QString::number(maxValue[0],'f',3));//"%1").arg(maxValue[0], 0, "g", 3));
            ui->minValue1->setText(QString::number(minValue[0],'f',3));
            ui->maxValue2->setText(QString::number(maxValue[1],'f',3));
            ui->minValue2->setText(QString::number(minValue[1],'f',3));
            ui->maxValue3->setText(QString::number(maxValue[2],'f',3));
            ui->minValue3->setText(QString::number(minValue[2],'f',3));
            ui->maxValue4->setText(QString::number(maxValue[3],'f',3));
            ui->minValue4->setText(QString::number(minValue[3],'f',3));
            ui->maxValue5->setText(QString::number(maxValue[4],'f',3));
            ui->minValue5->setText(QString::number(minValue[4],'f',3));
            ui->maxValue6->setText(QString::number(maxValue[5],'f',3));
            ui->minValue6->setText(QString::number(minValue[5],'f',3));
            ui->maxValue7->setText(QString::number(maxValue[6],'f',3));
            ui->minValue7->setText(QString::number(minValue[6],'f',3));
            ui->maxValue8->setText(QString::number(maxValue[7],'f',3));
            ui->minValue8->setText(QString::number(minValue[7],'f',3));
            ui->customPlot->xAxis->setRange(pingPongBuffer->
                    buffer[pingPongBuffer->currentReadBufferIndex].mathData[pingPongBuffer->bufferValidateDataLength-1].timeStamp,
                    pingPongBuffer->bufferValidateDataLength*D_VALID_RANGE_RATIO,Qt::AlignRight);

            float threshold1, threshold2;
            if (minYAxis > 0)
            {
                threshold1 = 0.5;
            }
            else
            {
                threshold1 = 1.5;
            }
            if (maxYAxis > 0)
            {
                threshold2 = 1.5;
            }
            else
            {
                threshold2 = 0.5;
            }
            ui->customPlot->yAxis->setRange(minYAxis*threshold1,maxYAxis*threshold2);
            ui->customPlot->replot();//hualei coredump ?
        }
    }



}



void MotorStatusView::addOneTimeData(MathDataInfo mathDataIn,bool isValid,int plotIndex,int dataType,int axisNumber,
                                     double magnification,int isDiffChecked)
{

    if ( isValid==false)
    {
        return ;
    }


    //一直添加数据点会导致２天后cpu消耗率达到１００％，　所以需要截取一定旧数据。cpu消耗高会导致界面卡、webHmi时间卡、电池校验错误、
    //雷达驱动soapError或　amcl超时。下面的处理方法还是有问题，过几天后即使暂停状态也会cpu过高１１０。
    double currentTimeStamp=mathDataIn.timeStamp;
    ui->customPlot->graph(plotIndex)->removeDataBefore(currentTimeStamp-validMaxDataLength);



    if ( dataType== 0)
    {
        mathDataIn.position_command[axisNumber]*= magnification;
        if(0==isDiffChecked)
        {
            ui->customPlot->graph(plotIndex)->addData(currentTimeStamp,
                 mathDataIn.position_command[axisNumber]);

            if (mathDataIn.position_command[axisNumber] < minValue[plotIndex])
            {
                minValue[plotIndex] = mathDataIn.position_command[axisNumber];
            }
            if (mathDataIn.position_command[axisNumber] > maxValue[plotIndex])
            {
                maxValue[plotIndex] = mathDataIn.position_command[axisNumber];
            }
        }
        else
        {
//            double diffVale;
//            if(0==dataArryIndex)
//            {
//                diffVale=pingPongBuffer->buffer[readIndex].mathData[dataArryIndex].position_command[axisNumber]-
//                        pingPongBuffer->buffer[pingPongBuffer->currentWriteBufferIndex].mathData[pingPongBuffer->bufferValidateDataLength-1]
//                        .position_command[axisNumber];

//            }
//            else
//            {
//                diffVale=pingPongBuffer->buffer[readIndex].mathData[dataArryIndex].position_command[axisNumber]-
//                        pingPongBuffer->buffer[readIndex].mathData[dataArryIndex-1].position_command[axisNumber];

//            }
//            ui->customPlot->graph(plotIndex)->addData(currentTimeStamp,
//                 diffVale);

//            if (diffVale < minValue[plotIndex])
//            {
//                minValue[plotIndex] = diffVale;
//            }
//            if (diffVale > maxValue[plotIndex])
//            {
//                maxValue[plotIndex] = diffVale;
//            }

        }

    }
    if ( dataType== 1)
    {
        mathDataIn.velocity_command[axisNumber] *= magnification;
        ui->customPlot->graph(plotIndex)->addData(currentTimeStamp,
                 mathDataIn.velocity_command[axisNumber]);
        if (mathDataIn.velocity_command[axisNumber] < minValue[plotIndex])
        {
            minValue[plotIndex] = mathDataIn.velocity_command[axisNumber];
        }
        if (mathDataIn.velocity_command[axisNumber] > maxValue[plotIndex])
        {
            maxValue[plotIndex] = mathDataIn.velocity_command[axisNumber];
        }
    }
    if ( dataType== 2)
    {
        mathDataIn.torque_command[axisNumber] *= magnification;
        ui->customPlot->graph(plotIndex)->addData(currentTimeStamp,
                 mathDataIn.torque_command[axisNumber]);
        if (mathDataIn.torque_command[axisNumber] < minValue[plotIndex])
        {
            minValue[plotIndex] = mathDataIn.torque_command[axisNumber];
        }
        if (mathDataIn.torque_command[axisNumber] > maxValue[plotIndex])
        {
            maxValue[plotIndex] = mathDataIn.torque_command[axisNumber];
        }
    }
    if ( dataType== 3)
    {
        mathDataIn.position_feedback[axisNumber] *= magnification;
        ui->customPlot->graph(plotIndex)->addData(currentTimeStamp,
                 mathDataIn.position_feedback[axisNumber]);
        if (mathDataIn.position_feedback[axisNumber] < minValue[plotIndex])
        {
            minValue[plotIndex] = mathDataIn.position_feedback[axisNumber];
        }
        if (mathDataIn.position_feedback[axisNumber] > maxValue[plotIndex])
        {
            maxValue[plotIndex] = mathDataIn.position_feedback[axisNumber];
        }
    }
    if ( dataType== 4)
    {
        mathDataIn.velocity_feedback[axisNumber] *= magnification;
        ui->customPlot->graph(plotIndex)->addData(currentTimeStamp,
                 mathDataIn.velocity_feedback[axisNumber]);
        if (mathDataIn.velocity_feedback[axisNumber] < minValue[plotIndex])
        {
            minValue[plotIndex] = mathDataIn.velocity_feedback[axisNumber];
        }
        if (mathDataIn.velocity_feedback[axisNumber] > maxValue[plotIndex])
        {
            maxValue[plotIndex] = mathDataIn.velocity_feedback[axisNumber];
        }
    }
    if ( dataType== 5)
    {
        mathDataIn.torque_feedback[axisNumber] *= magnification;
        ui->customPlot->graph(plotIndex)->addData(currentTimeStamp,
                 mathDataIn.torque_feedback[axisNumber]);
        if (mathDataIn.torque_feedback[axisNumber] < minValue[plotIndex])
        {
            minValue[plotIndex] = mathDataIn.torque_feedback[axisNumber];
        }
        if (mathDataIn.torque_feedback[axisNumber] > maxValue[plotIndex])
        {
            maxValue[plotIndex] = mathDataIn.torque_feedback[axisNumber];
        }
    }
    if ( dataType== 6)
    {
        mathDataIn.position_followOffset[axisNumber] *= magnification;
        ui->customPlot->graph(plotIndex)->addData(currentTimeStamp,
                 mathDataIn.position_followOffset[axisNumber]);
        if (mathDataIn.position_followOffset[axisNumber] < minValue[plotIndex])
        {
            minValue[plotIndex] = mathDataIn.position_followOffset[axisNumber];
        }
        if (mathDataIn.position_followOffset[axisNumber] > maxValue[plotIndex])
        {
            maxValue[plotIndex] = mathDataIn.position_followOffset[axisNumber];
        }
    }
    if ( dataType== 7)
    {
        mathDataIn.velocity_followOffset[axisNumber] *= magnification;
        ui->customPlot->graph(plotIndex)->addData(currentTimeStamp,
                 mathDataIn.velocity_followOffset[axisNumber]);
        if (mathDataIn.velocity_followOffset[axisNumber] < minValue[plotIndex])
        {
            minValue[plotIndex] = mathDataIn.velocity_followOffset[axisNumber];
        }
        if (mathDataIn.velocity_followOffset[axisNumber] > maxValue[plotIndex])
        {
            maxValue[plotIndex] = mathDataIn.velocity_followOffset[axisNumber];
        }
    }
    if ( dataType== 8)
    {
        mathDataIn.torque_followOffset[axisNumber] *= magnification;
        ui->customPlot->graph(plotIndex)->addData(currentTimeStamp,
                 mathDataIn.torque_followOffset[axisNumber]);
        if (mathDataIn.torque_followOffset[axisNumber] < minValue[plotIndex])
        {
            minValue[plotIndex] = mathDataIn.torque_followOffset[axisNumber];
        }
        if (mathDataIn.torque_followOffset[axisNumber] > maxValue[plotIndex])
        {
            maxValue[plotIndex] = mathDataIn.torque_followOffset[axisNumber];
        }
    }
    if ( dataType== 9)
    {
        mathDataIn.position_command_puls[axisNumber] *= magnification;
        ui->customPlot->graph(plotIndex)->addData(currentTimeStamp,
                 mathDataIn.position_command_puls[axisNumber]);
        if (mathDataIn.position_command_puls[axisNumber] < minValue[plotIndex])
        {
            minValue[plotIndex] = mathDataIn.position_command_puls[axisNumber];
        }
        if (mathDataIn.position_command_puls[axisNumber] > maxValue[plotIndex])
        {
            maxValue[plotIndex] = mathDataIn.position_command_puls[axisNumber];
        }
    }
    if ( dataType== 10)
    {
        mathDataIn.velocity_command_puls[axisNumber] *= magnification;
        ui->customPlot->graph(plotIndex)->addData(currentTimeStamp,
                 mathDataIn.velocity_command_puls[axisNumber]);
        if (mathDataIn.velocity_command_puls[axisNumber] < minValue[plotIndex])
        {
            minValue[plotIndex] = mathDataIn.velocity_command_puls[axisNumber];
        }
        if (mathDataIn.velocity_command_puls[axisNumber] > maxValue[plotIndex])
        {
            maxValue[plotIndex] = mathDataIn.velocity_command_puls[axisNumber];
        }
    }
    if ( dataType== 11)
    {
        mathDataIn.torque_command_puls[axisNumber] *= magnification;
        ui->customPlot->graph(plotIndex)->addData(currentTimeStamp,
                 mathDataIn.torque_command_puls[axisNumber]);
        if (mathDataIn.torque_command_puls[axisNumber] < minValue[plotIndex])
        {
            minValue[plotIndex] = mathDataIn.torque_command_puls[axisNumber];
        }
        if (mathDataIn.torque_command_puls[axisNumber] > maxValue[plotIndex])
        {
            maxValue[plotIndex] = mathDataIn.torque_command_puls[axisNumber];
        }
    }
    if ( dataType== 12)
    {
        mathDataIn.position_feedback_puls[axisNumber] *= magnification;
        ui->customPlot->graph(plotIndex)->addData(currentTimeStamp,
                 mathDataIn.position_feedback_puls[axisNumber]);
        if (mathDataIn.position_feedback_puls[axisNumber] < minValue[plotIndex])
        {
            minValue[plotIndex] = mathDataIn.position_feedback_puls[axisNumber];
        }
        if (mathDataIn.position_feedback_puls[axisNumber] > maxValue[plotIndex])
        {
            maxValue[plotIndex] = mathDataIn.position_feedback_puls[axisNumber];
        }
    }
    if ( dataType== 13)
    {
        mathDataIn.velocity_feedback_puls[axisNumber] *= magnification;
        ui->customPlot->graph(plotIndex)->addData(currentTimeStamp,
                 mathDataIn.velocity_feedback_puls[axisNumber]);
        if (mathDataIn.velocity_feedback_puls[axisNumber] < minValue[plotIndex])
        {
            minValue[plotIndex] = mathDataIn.velocity_feedback_puls[axisNumber];
        }
        if (mathDataIn.velocity_feedback_puls[axisNumber] > maxValue[plotIndex])
        {
            maxValue[plotIndex] = mathDataIn.velocity_feedback_puls[axisNumber];
        }
    }
    if ( dataType== 14)
    {
        mathDataIn.torque_feedback_puls[axisNumber] *= magnification;
        ui->customPlot->graph(plotIndex)->addData(currentTimeStamp,
                 mathDataIn.torque_feedback_puls[axisNumber]);
        if (mathDataIn.torque_feedback_puls[axisNumber] < minValue[plotIndex])
        {
            minValue[plotIndex] = mathDataIn.torque_feedback_puls[axisNumber];
        }
        if (mathDataIn.torque_feedback_puls[axisNumber] > maxValue[plotIndex])
        {
            maxValue[plotIndex] = mathDataIn.torque_feedback_puls[axisNumber];
        }
    }
    if ( dataType== 15)
    {
        mathDataIn.position_followOffset_puls[axisNumber] *= magnification;
        ui->customPlot->graph(plotIndex)->addData(currentTimeStamp,
                 mathDataIn.position_followOffset_puls[axisNumber]);
        if (mathDataIn.position_followOffset_puls[axisNumber] < minValue[plotIndex])
        {
            minValue[plotIndex] = mathDataIn.position_followOffset_puls[axisNumber];
        }
        if (mathDataIn.position_followOffset_puls[axisNumber] > maxValue[plotIndex])
        {
            maxValue[plotIndex] = mathDataIn.position_followOffset_puls[axisNumber];
        }
    }
    if ( dataType== 16)
    {
        mathDataIn.velocity_followOffset_puls[axisNumber] *= magnification;
        ui->customPlot->graph(plotIndex)->addData(currentTimeStamp,
                 mathDataIn.velocity_followOffset_puls[axisNumber]);
        if (mathDataIn.velocity_followOffset_puls[axisNumber] < minValue[plotIndex])
        {
            minValue[plotIndex] = mathDataIn.velocity_followOffset_puls[axisNumber];
        }
        if (mathDataIn.velocity_followOffset_puls[axisNumber] > maxValue[plotIndex])
        {
            maxValue[plotIndex]  = mathDataIn.velocity_followOffset_puls[axisNumber];
        }
    }
    if ( dataType== 17)
    {
        mathDataIn.torque_followOffset_puls[axisNumber] *= magnification;
        ui->customPlot->graph(plotIndex)->addData(currentTimeStamp,
                 mathDataIn.torque_followOffset_puls[axisNumber]);
        if (mathDataIn.torque_followOffset_puls[axisNumber] < minValue[plotIndex] )
        {
            minValue[plotIndex]  = mathDataIn.torque_followOffset_puls[axisNumber];
        }
        if (mathDataIn.torque_followOffset_puls[axisNumber] > maxValue[plotIndex] )
        {
            maxValue[plotIndex]  = mathDataIn.torque_followOffset_puls[axisNumber];
        }
    }
    if ( dataType== 18)
    {
        mathDataIn.velocity_offset_command_puls[axisNumber] *= magnification;
        ui->customPlot->graph(plotIndex)->addData(currentTimeStamp,
                 mathDataIn.velocity_offset_command_puls[axisNumber]);
        if (mathDataIn.velocity_offset_command_puls[axisNumber] < minValue[plotIndex])
        {
            minValue[plotIndex] = mathDataIn.velocity_offset_command_puls[axisNumber];
        }
        if (mathDataIn.velocity_offset_command_puls[axisNumber] > maxValue[plotIndex])
        {
            maxValue[plotIndex] = mathDataIn.velocity_offset_command_puls[axisNumber];
        }
    }
    if ( dataType== 19)
    {
        mathDataIn.torque_offset_command_puls[axisNumber] *= magnification;
        ui->customPlot->graph(plotIndex)->addData(currentTimeStamp,
                 mathDataIn.torque_offset_command_puls[axisNumber]);
        if (mathDataIn.torque_offset_command_puls[axisNumber] < minValue[plotIndex])
        {
            minValue[plotIndex] = mathDataIn.torque_offset_command_puls[axisNumber];
        }
        if (mathDataIn.torque_offset_command_puls[axisNumber] > maxValue[plotIndex])
        {
            maxValue[plotIndex] = mathDataIn.torque_offset_command_puls[axisNumber];
        }
    }
    if ( dataType== 20)
    {
        mathDataIn.velocity_offset_command[axisNumber] *= magnification;
        ui->customPlot->graph(plotIndex)->addData(currentTimeStamp,
                 mathDataIn.velocity_offset_command[axisNumber]);
        if (mathDataIn.velocity_offset_command[axisNumber] < minValue[plotIndex])
        {
            minValue[plotIndex] = mathDataIn.velocity_offset_command[axisNumber];
        }
        if (mathDataIn.velocity_offset_command[axisNumber] > maxValue[plotIndex])
        {
            maxValue[plotIndex] = mathDataIn.velocity_offset_command[axisNumber];
        }
    }
    if ( dataType== 21)
    {
        mathDataIn.torque_offset_command[axisNumber] *= magnification;
        ui->customPlot->graph(plotIndex)->addData(currentTimeStamp,
                 mathDataIn.torque_offset_command[axisNumber]);
        if (mathDataIn.torque_offset_command[axisNumber] < minValue[plotIndex])
        {
            minValue[plotIndex] = mathDataIn.torque_offset_command[axisNumber];
        }
        if (mathDataIn.torque_offset_command[axisNumber] > maxValue[plotIndex])
        {
            maxValue[plotIndex] = mathDataIn.torque_offset_command[axisNumber];
        }
    }

    //for virtualLine------------
    double tmpKey,tmpValue;
    if ( dataType== 22)
    {
        tmpKey=mathDataIn.timeStamp;
        tmpValue=mathDataIn.vehiclePositionCommand[axisNumber];
        tmpValue*=magnification;
        ui->customPlot->graph(plotIndex)->addData(tmpKey,tmpValue);
        if (tmpValue < minValue[plotIndex])
        {
            minValue[plotIndex] =tmpValue;
        }
        if (tmpValue> maxValue[plotIndex])
        {
            maxValue[plotIndex] = tmpValue;
        }
    }
    if ( dataType== 23)
    {
        tmpKey=mathDataIn.timeStamp ;
        tmpValue= mathDataIn.vehiclePositionFeedback[axisNumber];
        tmpValue*=magnification;
        ui->customPlot->graph(plotIndex)->addData(tmpKey,tmpValue);
        if (tmpValue < minValue[plotIndex])
        {
            minValue[plotIndex] =tmpValue;
        }
        if (tmpValue> maxValue[plotIndex])
        {
            maxValue[plotIndex] = tmpValue;
        }
    }
    if ( dataType== 24)
    {
        mathDataIn.deltaDistance_x *= magnification;
        ui->customPlot->graph(plotIndex)->addData(mathDataIn.timeStamp,
                 mathDataIn.deltaDistance_x);
        if (mathDataIn.deltaDistance_x< minValue[plotIndex])
        {
            minValue[plotIndex] = mathDataIn.deltaDistance_x;
        }
        if (mathDataIn.deltaDistance_x > maxValue[plotIndex])
        {
            maxValue[plotIndex] = mathDataIn.deltaDistance_x;
        }
    }

    if ( dataType== 25)
    {
        mathDataIn.deltaAngle *= magnification;
        ui->customPlot->graph(plotIndex)->addData(currentTimeStamp,
                 mathDataIn.deltaAngle);
        if (mathDataIn.deltaAngle < minValue[plotIndex])
        {
            minValue[plotIndex] = mathDataIn.deltaAngle;
        }
        if (mathDataIn.deltaAngle > maxValue[plotIndex])
        {
            maxValue[plotIndex] = mathDataIn.deltaAngle;
        }
    }
    if ( dataType== 26)
    {
        mathDataIn.absoluteDistance*= magnification;
        ui->customPlot->graph(plotIndex)->addData(currentTimeStamp,
                 mathDataIn.absoluteDistance);
        if (mathDataIn.absoluteDistance< minValue[plotIndex])
        {
            minValue[plotIndex] = mathDataIn.absoluteDistance;
        }
        if (mathDataIn.absoluteDistance > maxValue[plotIndex])
        {
            maxValue[plotIndex] = mathDataIn.absoluteDistance;
        }
    }
    if ( dataType== 27)
    {
        mathDataIn.absoluteAngle*= magnification;
        ui->customPlot->graph(plotIndex)->addData(currentTimeStamp,
                 mathDataIn.absoluteAngle);
        if (mathDataIn.absoluteAngle < minValue[plotIndex])
        {
            minValue[plotIndex] = mathDataIn.absoluteAngle;
        }
        if (mathDataIn.absoluteAngle> maxValue[plotIndex])
        {
            maxValue[plotIndex] = mathDataIn.absoluteAngle;
        }
    }
    if ( dataType== 28)
    {
        mathDataIn.anglePidOutput*= magnification;
        ui->customPlot->graph(plotIndex)->addData(currentTimeStamp,
                 mathDataIn.anglePidOutput);
        if (mathDataIn.anglePidOutput< minValue[plotIndex])
        {
            minValue[plotIndex] = mathDataIn.anglePidOutput;
        }
        if (mathDataIn.anglePidOutput > maxValue[plotIndex])
        {
            maxValue[plotIndex] = mathDataIn.anglePidOutput;
        }
    }
    if ( dataType== 29)
    {
        mathDataIn.xPidOutput *= magnification;
        ui->customPlot->graph(plotIndex)->addData(currentTimeStamp,
                 mathDataIn.xPidOutput);
        if (mathDataIn.xPidOutput < minValue[plotIndex])
        {
            minValue[plotIndex] = mathDataIn.xPidOutput;
        }
        if (mathDataIn.xPidOutput> maxValue[plotIndex])
        {
            maxValue[plotIndex] = mathDataIn.xPidOutput;
        }
    }
    if ( dataType== 30)
    {
        mathDataIn.deltaDistance_y*= magnification;
        ui->customPlot->graph(plotIndex)->addData(currentTimeStamp,
                 mathDataIn.deltaDistance_y);
        if (mathDataIn.deltaDistance_y < minValue[plotIndex])
        {
            minValue[plotIndex] = mathDataIn.deltaDistance_y;
        }
        if (mathDataIn.deltaDistance_y > maxValue[plotIndex])
        {
            maxValue[plotIndex] = mathDataIn.deltaDistance_y;
        }
    }
    if ( dataType== 31)
    {
        mathDataIn.yPidOutput *= magnification;
        ui->customPlot->graph(plotIndex)->addData(currentTimeStamp,
                 mathDataIn.yPidOutput);
        if (mathDataIn.yPidOutput < minValue[plotIndex])
        {
            minValue[plotIndex] = mathDataIn.yPidOutput;
        }
        if (mathDataIn.yPidOutput > maxValue[plotIndex])
        {
            maxValue[plotIndex] = mathDataIn.yPidOutput;
        }
    }
    if ( dataType== 32)
    {
        mathDataIn.aDin[axisNumber] *= magnification;
        ui->customPlot->graph(plotIndex)->addData(currentTimeStamp,
                 mathDataIn.aDin[axisNumber]);
        if (mathDataIn.aDin[axisNumber] < minValue[plotIndex])
        {
            minValue[plotIndex] = mathDataIn.aDin[axisNumber];
        }
        if (mathDataIn.aDin[axisNumber] > maxValue[plotIndex])
        {
            maxValue[plotIndex] = mathDataIn.aDin[axisNumber];
        }
    }
    //
    if ( dataType== 33)
    {
        mathDataIn.idealTorque[axisNumber] *= magnification;
        ui->customPlot->graph(plotIndex)->addData(currentTimeStamp,
                 mathDataIn.idealTorque[axisNumber]);
        if (mathDataIn.idealTorque[axisNumber] < minValue[plotIndex])
        {
            minValue[plotIndex] = mathDataIn.idealTorque[axisNumber];
        }
        if (mathDataIn.idealTorque[axisNumber] > maxValue[plotIndex])
        {
            maxValue[plotIndex] = mathDataIn.idealTorque[axisNumber];
        }
    }
    if ( dataType== 34)
    {
        mathDataIn.torqueBias[axisNumber] *= magnification;
        ui->customPlot->graph(plotIndex)->addData(currentTimeStamp,
                 mathDataIn.torqueBias[axisNumber]);
        if (mathDataIn.torqueBias[axisNumber] < minValue[plotIndex])
        {
            minValue[plotIndex] = mathDataIn.torqueBias[axisNumber];
        }
        if (mathDataIn.torqueBias[axisNumber] > maxValue[plotIndex])
        {
            maxValue[plotIndex] = mathDataIn.torqueBias[axisNumber];
        }
    }

}

void MotorStatusView::setButtonStyle(int flag)
{
    if(1==flag)
    {
        //color
        QPalette pal = ui->pushButton->palette();
        pal.setColor(QPalette::Button,Qt::green);
        ui->pushButton->setPalette(pal);
        ui->pushButton->setAutoFillBackground(true);
        ui->pushButton->setFlat(true);
        //color
        pal = ui->pushButton_2->palette();
        pal.setColor(QPalette::Button,Qt::gray);
        ui->pushButton_2->setPalette(pal);
        ui->pushButton_2->setAutoFillBackground(true);
        ui->pushButton_2->setFlat(true);
        //color
        pal = ui->pushButton_3->palette();
        pal.setColor(QPalette::Button,Qt::gray);
        ui->pushButton_3->setPalette(pal);
        ui->pushButton_3->setAutoFillBackground(true);
        ui->pushButton_3->setFlat(true);
    }
    else if(2==flag)
    {
        //color
        QPalette pal = ui->pushButton->palette();
        pal.setColor(QPalette::Button,Qt::gray);
        ui->pushButton->setPalette(pal);
        ui->pushButton->setAutoFillBackground(true);
        ui->pushButton->setFlat(true);
        //color
        pal = ui->pushButton_2->palette();
        pal.setColor(QPalette::Button,Qt::green);
        ui->pushButton_2->setPalette(pal);
        ui->pushButton_2->setAutoFillBackground(true);
        ui->pushButton_2->setFlat(true);
        //color
        pal = ui->pushButton_3->palette();
        pal.setColor(QPalette::Button,Qt::gray);
        ui->pushButton_3->setPalette(pal);
        ui->pushButton_3->setAutoFillBackground(true);
        ui->pushButton_3->setFlat(true);
    }
    else
    {
        //color
        QPalette pal = ui->pushButton->palette();
        pal.setColor(QPalette::Button,Qt::red);
        ui->pushButton->setPalette(pal);
        ui->pushButton->setAutoFillBackground(true);
        ui->pushButton->setFlat(true);
        //color
        pal = ui->pushButton_2->palette();
        pal.setColor(QPalette::Button,Qt::gray);
        ui->pushButton_2->setPalette(pal);
        ui->pushButton_2->setAutoFillBackground(true);
        ui->pushButton_2->setFlat(true);
        //color
        pal = ui->pushButton_3->palette();
        pal.setColor(QPalette::Button,Qt::gray);
        ui->pushButton_3->setPalette(pal);
        ui->pushButton_3->setAutoFillBackground(true);
        ui->pushButton_3->setFlat(true);
    }

}

void MotorStatusView::changeLanguage()
{
    ui->retranslateUi(this);
    setViewText();
}

void MotorStatusView::setViewText()
{
    ui->blue_comboBox->setItemText(0, tr("无"));
    ui->red_comboBox->setItemText(0, tr("无"));
    ui->green_comboBox->setItemText(0, tr("无"));
    ui->black_comboBox->setItemText(0, tr("无"));
    ui->yellow_comboBox->setItemText(0, tr("无"));

    model->setHeaderData(0,Qt::Horizontal,tr("轴"));
    model->setHeaderData(1,Qt::Horizontal,tr("位置"));
    model->setHeaderData(2,Qt::Horizontal,tr("速度"));
    model->setHeaderData(3,Qt::Horizontal,tr("力距"));
    model->setHeaderData(4,Qt::Horizontal,tr("误差"));
    model->setHeaderData(5,Qt::Horizontal,tr("功率"));
    model->setHeaderData(6,Qt::Horizontal,tr("位置最大值"));
    model->setHeaderData(7,Qt::Horizontal,tr("速度最大值"));
    model->setHeaderData(8,Qt::Horizontal,tr("力距最大值"));
    model->setHeaderData(9,Qt::Horizontal,tr("误差最大值"));
    model->setHeaderData(10,Qt::Horizontal,tr("功率最大值"));
}

void MotorStatusView::on_horizontalSlider_sliderMoved(int position)
{
    ui->customPlot->xAxis->setRange(clickedX-position*20,mainKey+position*20);
    ui->customPlot->replot();
}

void MotorStatusView::on_verticalSlider_sliderMoved(int position)
{

    ui->customPlot->yAxis->setRange(clickedY-position*3,clickedY+position*3);
//    ui->customPlot->yAxis->setRange(clickedY-position,clickedY+position);
    ui->customPlot->replot();
}

void MotorStatusView::on_pushButton_4_clicked()
{
    receiveWaveData(true);
}
